home *** CD-ROM | disk | FTP | other *** search
- -- card: 11064 from stack: in
- -- bmap block id: 0
- -- flags: 0000
- -- background id: 9703
- -- name:
-
-
- -- part contents for background part 3
- ----- text -----
- hp2pict.inc.c
-
- -- part contents for background part 2
- ----- text -----
-
- /* hp2pict.inc.c
- *
- *
- * Copyright 1990 by d.g.gilbert.
- * dogStar Software && Indiana University Biology Dept.
- * email: gilbertd@iubio.bio.indiana.edu
- *
- */
-
-
-
- /* hp2pict routines & data */
-
- /* A4: 10800 x, 7680 y -- GCG driver: 10170-44x, 7840-384y */
- /* A3: 15200 x, 10800 y -- GCG driver: 16000-0x, 10170-34y*/
- /* 9600 x 7200 == PlotGram idea of hp pagesize */
- #define hpPageX 10800 /*10800 */ /*10170 - 44 */
- #define hpPageY 7680 /*7456*/ /*7680 */
-
- #define LBEND '~' /* LaBel end char, was 3 (^C),
- need non-control to work in HCard field...
- 'ΓÇá' -- !! HI ascii is missed by this C !! */
-
-
- /*
- MUST #INCLUDE <MATH.H>
- or get garbage at runtime without warning
- */
- int itan2( float x, float y)
- { /* == atan2, but return angle as int degrees (0..360) */
- #define mpi 3.1415926
- int r;
-
- if (x==0.0 && y==0.0) r = 360;
- else if (x==0.0) r = 0;
- else if (y==0.0) r = 90;
- else r = (180.0/mpi * atan(fabs(x/y)));
- if (y < 0.0) r = 180 - r;
- r = abs(r);
- if (x < 0.0) r = 360 - r;
- return r;
- } /* itan2 */
-
- void lineit(int linetype, int dashsize)
- { /* ?? need turtlegraphics to do dashed lines ? */
- /* not working yet */
-
- switch (linetype) {
- case 0:
- /* dashstop(); */
- break;
- default:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- dashsize = dashsize;
- /* dashline(dashsize); */
- break;
- }
- }
-
-
-
- void laserline( int num, int denom)
- /* set postscript line width (rel to 1/72 dpi);
- use num=1, denom=4 for 1/300 dpi line */
- {
- #define SetLineWidth 182
- Point **linesize;
-
- (Handle) linesize = NewHandle(sizeof(Point));
- (**linesize).v = num;
- (**linesize).h = denom;
- PicComment( SetLineWidth, sizeof(Point), (Handle) linesize);
- DisposHandle( (Handle) linesize);
- } /*laserline*/
-
-
-
-
- void drawUpstr(int h, int v, int rotnum, char *s)
- {
- #define maxd 24
- #define maxdb 4 /* must be even */
- #define maxw 816 /* was 512 */
- #define maxwb 102 /* was 64 -- must be even */
-
- typedef char sbitarray[maxd][maxwb];
- typedef char tbitarray[maxw][maxdb];
-
- sbitarray *sbits, *sbit2;
- tbitarray *tbits;
- Ptr tp;
- int w,d,i,j;
- Rect tor, sor;
- FontInfo fi;
- BitMap smap, smap2, tmap;
- GrafPtr aport, offport;
-
-
- GetPort( &aport); /* !! may be CGrafPort w/ pixmap */
- GetFontInfo(&fi);
- d = min(maxd-1, fi.ascent + fi.descent + fi.leading);
- w = min(maxw-1, stringwidth(s));
- /* h = h - (d / 2); */ /*let h,v == topleft not center*/
- /* v = v - (w / 2); */
- SetRect( &tor, h, v, h + d, v + w);
- SetRect( &sor, h, v, h + w, v + d);
-
- (Ptr)sbits = NewPtr(sizeof(sbitarray));
- for (i=0; i<sizeof(sbitarray); i++) ((char *)sbits)[i] = 0;
- smap.baseAddr = (Ptr)sbits;
- if ((long)smap.baseAddr % 2 == 1) ++smap.baseAddr; /* if odd(addr) */
- smap.rowBytes = maxwb;
- SetRect( &smap.bounds, 0, 0, w, d);
-
- switch (rotnum) {
- case 2:
- (Ptr)sbit2 = NewPtr(sizeof(sbitarray));
- for (i=0; i<sizeof(sbitarray); i++) ((char *)sbit2)[i] = 0;
- smap2.baseAddr = (Ptr)sbit2;
- if ((long)smap2.baseAddr % 2 == 1) ++smap2.baseAddr;
- smap2.rowBytes = maxwb;
- SetRect( &smap2.bounds, 0, 0, w, d);
- break;
-
- case 1:
- case 3:
- (Ptr)tbits = NewPtr(sizeof(tbitarray));
- for (i=0; i<sizeof(tbitarray); i++) ((char *)tbits)[i] = 0;
- tmap.baseAddr = (Ptr)tbits;
- if ((long)tmap.baseAddr % 2 == 1) ++tmap.baseAddr;
- tmap.rowBytes = maxdb;
- SetRect( &tmap.bounds, 0, 0, d, w);
- break;
- }
-
- (Ptr) offport = NewPtr(sizeof(GrafPort)); /* forget CGrafPort */
- OpenPort( offport);
- SetPortBits( &smap); /* set our offscreen map */
- TextFont( aport->txFont);
- TextSize( aport->txSize);
- TextFace( aport->txFace);
- MoveTo(0, fi.ascent);
- drawstring(s); /* draw the bugger */
- ClosePort( offport);
- DisposPtr( (Ptr)offport);
- SetPort( aport);
-
- switch (rotnum) {
-
- case 2: /* 180┬░ ???*/
- for (i=0; i < w; i++) {
- for (j = 0; j < d; j++)
- if (BitTst( &((*sbits)[j][0]), i))
- BitSet( &((*sbit2)[d-j][0]), w-i);
- }
- OffsetRect( &sor, -w, 0/*-d*/); /* ? */
- CopyBits( &smap2, &(aport->portBits), &smap2.bounds, &sor,
- srcOr, NULL);
- DisposPtr( (Ptr)sbit2);
- break;
-
- case 0: /* here for completeness, or just drawstring */
- CopyBits( &smap, &(aport->portBits), &smap.bounds, &sor,
- srcOr, NULL);
- break;
-
-
- case 3: /* = 270┬░, bottom left is start */
- for (i = w - 1; i >= 0; i--) {
- tp = &((*tbits)[w - (i + 1)][0]);
- for ( j = 0; j < d; j++)
- if (BitTst( &((*sbits)[j][0]), i)) BitSet(tp, j);
- }
- OffsetRect( &tor, -d, -w); /* ! */
- CopyBits( &tmap, &(aport->portBits), &tmap.bounds, &tor,
- srcOr, NULL);
- DisposPtr( (Ptr)tbits);
- break;
-
- case 1: /* = 90┬░, top right is start */
- for (i = 0; i<w; i++) {
- tp = &((*tbits)[i][0]);
- for (j = d - 1; j >= 0; j--)
- if (BitTst( &((*sbits)[j][0]), i)) BitSet(tp, d - (j + 1));
- }
- CopyBits( &tmap, &(aport->portBits), &tmap.bounds, &tor,
- srcOr, NULL);
- DisposPtr( (Ptr)tbits);
- break;
- }
-
- DisposPtr( (Ptr)sbits);
- } /* drawUpstr */
-
-
-
- void textPicDraw(int h, int v, int rot, char *s)
- {
- /* MacDraw standard drawString w/ rotation
- h,v = _center_ of text rect
- */
- #define textBegin 150
- #define textEnd 151
- #define textCenter 154
-
- typedef struct {
- char tjus; /* 0..4 == left,cent,right,full just */
- char tflip; /* 0..2 == 0,horiz,vert flip */
- short trot; /* 0..360 rotate */
- char tline; /* 1,2,3 line spacing */
- char tcmnt; /* reserved */
- } TxtPicRec, *pTxtPicRec, **hTxtPicRec;
-
- typedef struct {
- Fixed y, x;
- } TxtCenter, *pTxtCenter, **hTxtCenter;
-
- int w, d, rotnum;
- Rect zerorect;
- FontInfo fi;
- hTxtPicRec picdat;
- hTxtCenter xydat;
- RgnHandle saveclip;
-
- rotnum = ((rot+44) % 360) / 90;
- GetFontInfo( &fi);
- d = (fi.ascent + fi.descent + fi.leading) / 2;
- w = stringwidth(s) / 2;
- MoveTo( h, v); /* ?? for HP text */
- /* MoveTo(h - w, v - d); */ /* move from center */
-
- (Handle) picdat = NewHandle(sizeof(TxtPicRec));
- (**picdat).tjus = 1;
- (**picdat).tflip = 0;
- (**picdat).trot = rot % 360;
- (**picdat).tline = 1;
- (**picdat).tcmnt = 0;
- PicComment(textBegin, 6, (Handle) picdat);
- DisposHandle( (Handle) picdat);
-
- (Handle)xydat = NewHandle(sizeof(TxtCenter));
- (**xydat).x = Long2Fix(0);
- (**xydat).y = Long2Fix(0);
- PicComment( textCenter, 8, (Handle)xydat);
- DisposHandle( (Handle)xydat);
-
- if (rotnum == 0) drawstring(s);
- else {
- saveclip = NewRgn();
- GetClip( saveclip);
- SetRect( &zerorect, 0,0,0,0);
- ClipRect( &zerorect);
- drawstring(s);
- SetClip( saveclip);
- DisposeRgn( saveclip);
- drawUpstr( h, v, rotnum, s);
- }
- PicComment( textEnd, 0, NULL);
- } /*textPicDraw*/
-
-
-
-
-
- #define map2pic(x,y,h,v) { \
- h = picrect->left + (x / xscale); \
- v = picrect->top + ((ymax - y) / yscale); \
- }
- #define maprel2pic(x,y,h,v) { \
- h = (x / xscale); v = (( - y) / yscale); \
- }
-
- PicHandle hp2pict( Boolean forpage, Rect *picrect, Handle hbuf,
- WindowPtr myWind, Boolean *alldone)
- {
- char *c, *ce, *si, s[256];
- int cmd, hpx, hpy, x, y, xd, yd, h, v, k, pageno;
- Boolean dorel, atend, done, moveit, penup;
- Rect wr, hprect;
- Point pt;
- float fx, fy, linedash, xscale, yscale;
- int linetype, ymax, rot = 0;
- RGBColor bcolor;
- PicHandle pic;
-
- HLock( hbuf);
- c = (char *) (*hbuf);
- while ((*c != 0) & (*c != ';')) c++;
- if (*c == ';') c++;
- hpx = hpPageX;
- hpy = hpPageY;
-
- redraw:
-
- pageno = 0;
- *alldone = false;
- pic = OpenPicture(picrect);
- if (forpage) {
- InsetRect( picrect, 5, 5);
- }
- else {
- InsetRect( picrect, 10, 10);
- OffsetRect( picrect, 0, 5);
- ShowPen();
- if (hasColorQD()) {
- bcolor.red = 56000;
- bcolor.green= 60000;
- bcolor.blue = 65000;
- if (lotsOfColor(myWind)) RGBBackColor( &bcolor);
- EraseRect( &myWind->portRect);
- }
- }
- SetRect( &wr, -10000, -10000, 30000, 30000);
- ClipRect(&wr);
-
- TextFont(times);
- if (forpage) TextSize(12);
- else TextSize(9);
- laserline(1, 2);
- PenNormal();
- penup = true;
- dorel = false;
- linetype = 0;
- linedash = 1;
-
- SetRect( &hprect, 0, 0, hpx, hpy);
- ymax = hpy;
- xscale = hpx / (picrect->right - picrect->left);
- yscale = hpy / (picrect->bottom - picrect->top);
-
- done = (*c == 0);
-
- while (!done) {
- while ((!Isalpha(*c)) && (*c != 0)) c++; /* skip to start of cmd */
- /* ^^ this messes up '\27.' end of transmission */
-
- cmd = (Toupper(*c++))*256 + (Toupper(*c++));
- atend = false;
-
- switch (cmd) {
-
- case '\27.': /* 6958 == '\27.' */ /* not seen ? */
- if (*c == ')') {
- atend = true;
- done = true;
- *alldone = true;
- *c = 0;
- }
- break;
-
- case 'AF':
- /* the end-of-plot signal is "AF;\27.)x" */
- /* multi-page plots will want me to throw up a new
- plot window -> from Draw */
- if ( (++pageno > 1) | (c[1] == '\27' & c[3] == ')') ) {
- atend = true;
- done = true;
- *c = 0;
- /* SysBeep(1); */
- }
- break; /* autopage */
-
- case 'IN':
- /* the start-of-plot signal for GCG is */
- /* "\27.(\27.N;19:\27.I81;;17:IN;...AF;" */
- break; /* initialize */
-
- case 'AA': break; /* arc */
- case 'IP': break; /* frame */
-
- case 'LB':
- for (si=0; *c != LBEND & si < 256; si++, c++)
- s[si] = *c;
- s[si] = 0;
- /* drawstring(s); */
- /* -- use last valid h,v, rot */
- /* Note: this h,v is left,top? of string, not center */
- textPicDraw( h, v, rot, s);
- ++c; atend = true;
- break; /* LBlabel^C; */
-
- case 'LO':
- x = Strtod( c, &ce); if (ce == c) break;
- c = ce;
- break; /* ? Label Offset move ?? */
-
- case 'LT':
- k = linetype;
- linetype = 0;
- if (*c != ';') {
- linetype = Strtod( c, &ce);
- if (ce != c) {
- c = ce; if (*c == ',') c++;
- linedash = Strtod( c, &ce);
- c = ce;
- }
- }
- if (linetype != k | linetype > 0) {
- maprel2pic(linedash,linedash, xd, yd);
- xd = max( abs(xd), abs(yd));
- lineit( linetype, xd);
- }
- break; /* LT#,#; line type (style, %diag) */
-
- case 'PU':
- penup = true;
- if (*c == ';') break;
- x = Strtod( c, &ce); if (ce == c) break;
- c = ce; if (*c == ',') c++;
- y = Strtod( c, &ce); if (ce == c) break;
- c = ce;
- map2pic( x, y, h, v);
- MoveTo(h,v);
- break; /* PU[#,#];penup */
-
- case 'PR': /* PR#,#[...]; rel move */
- dorel = true;
- goto penat;
-
- case 'PD': /* PD[#,#,...]; pendn */
- penup = false;
- goto penat; /* slide into PA loop */
-
- case 'PA':
- dorel = false;
- moveit = (*c != ',');
- penat:
- do {
- if (*c == ',') c++;
- x = Strtod( c, &ce); if (ce == c) break;
- c = ce; if (*c == ',') c++;
- y = Strtod( c, &ce); if (ce == c) break;
- c = ce;
- if (dorel) {
- maprel2pic( x, y, h, v);
- if (penup | moveit) Move(h,v);
- else Line(h,v);
- GetPen(&pt);
- h = pt.h; v = pt.v; /* save for LB */
- }
- else {
- map2pic( x, y, h, v);
- if (penup | moveit) MoveTo(h,v);
- else LineTo(h,v);
- }
- moveit = false;
- } while (true);
- break; /* PA#,#[,#,#...]; mvabs */
-
- case 'RO':
- x = Strtod( c, &ce);
- if ((x > 60 & x < 120) && !forpage) {
- /* can't do for printed page?? -- need to mangle
- page orientation in pageSetup... */
- hpx = hpPageY;
- hpy = hpPageX;
-
- xd = picrect->right;
- picrect->right = picrect->bottom;
- picrect->bottom = xd;
-
- if (!forpage) HidePen();
- ClosePicture();
- KillPicture( pic);
-
- xd = myWind->portRect.right - myWind->portRect.left;
- yd = myWind->portRect.bottom - myWind->portRect.top;
- SizeWindow( myWind, yd, xd, true);
- BringToFront( myWind);
- goto redraw;
- }
- break; /* RO#; rotate plot */
-
- case 'SP':
- x = Strtod( c, &ce);
- switch (x) {
- /* pen colors should be user option */
- /* this form works w/ PICT1(b/w) as well as PICT2 */
- default:
- case 1: ForeColor(blackColor); break;
- case 2: ForeColor(greenColor); break;
- case 3: ForeColor(blueColor); break;
- case 4: ForeColor(redColor); break;
- case 5: ForeColor(cyanColor); break;
- case 6: ForeColor(magentaColor); break;
- case 7: ForeColor(yellowColor); break;
- case 8: ForeColor(blackColor); break;
- }
- /* set color to # */
- break; /* SP[#]; select pen */
-
- case 'SI':
- if (*c == ';') break;
- fx = Strtod( c, &ce); if (ce == c) break;
- c = ce; if (*c == ',') c++;
- fy = Strtod( c, &ce); if (ce == c) break;
- c = ce;
- /* map fx,fy into TextSize ?? */
- break; /* SI#,#; set text abs width,abs height ? */
-
- case 'DI':
- rot = 0;
- if (*c == ';') break;
- fy = Strtod( c, &ce); if (ce == c) break;
- c = ce; if (*c == ',') c++;
- fx = Strtod( c, &ce); if (ce == c) break;
- c = ce;
- rot = itan2( fx, fy);
- break; /* DI#,#; text direction */
- /* (run = cos(direction), rise = sin(direction) */
-
- case 'SL':
- break; /* SL[#]; set text slant (tangent) ? */
-
- case 'SC': break; /* scale */
- case 'VS': break; /* VS#; pen speed */
-
- case 'CI': /* filled oval */
- x = Strtod( c, &ce); if (ce == c) break;
- c = ce; if (*c == ',') c++;
- y = Strtod( c, &ce); if (ce == c) break;
- c = ce;
- maprel2pic( x+1, y+1, h, v);
- h = min(h,abs(v)); /* h is bad(huge) for card-sized plot */
- GetPen(&pt);
- SetRect(&wr, pt.h, pt.v, pt.h, pt.v);
- InsetRect(&wr, -h, -h);
- /* FillOval(&wr, black); */
- PaintOval(&wr);
- break;
-
- default : break;
- }
-
- if (!atend)
- while ((*c != 0) && (*c != ';') && (!Isalpha(*c)))
- c++; /* skip to end cmd */
- if (*c == ';') c++;
-
- if (*c == 0) done = true;
- }
-
- if (!forpage) HidePen();
- ClosePicture();
- HUnlock( hbuf);
-
- return pic;
-
- } /* hp2pict */
-